package lab03.test01;

import java.io.*;

public class Test01 {
    public static void main(String[] args) {

        /*
        读文件基本操作：读一个文件并打印文件内容
         */

        String path = "D://java实验//lab03test01.txt";

        //1.字符流来读
        //1.1 一次读一行字符
        try {
            BufferedReader reader = new BufferedReader(new FileReader(path));

            String line = "";
            line = reader.readLine();
            System.out.println(line);
            reader.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        //2.字节流写文件
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(path);
            //1010100-byte
            //每一次写的是一个或多个整数
            fileOutputStream.write(65);

            byte a;
            byte[] data = new byte[3];
            data[0] = 65;
            data[1] = 22;
            data[2] = 44;

            fileOutputStream.write(data);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
